<link rel="stylesheet" type="text/css" href="<?php echo ADMIN_COMPONENT_PATH.COMPONENT_PATH."css/datepicker.css"; ?>" />
<script type="text/javascript" src="<?php echo ADMIN_COMPONENT_PATH.COMPONENT_PATH."js/date.js"; ?>"></script>
<script type="text/javascript" src="<?php echo ADMIN_COMPONENT_PATH.COMPONENT_PATH."js/jquery.datePicker.js"; ?>"></script>
<script type="text/javascript">
Date.firstDayOfWeek = 0;
Date.format = 'mm/dd/yyyy';
$(document).ready(function() {
	$('.date_pick').datePicker();
	$('.StartDate').bind(
			'dpClosed',
			function(e, selectedDates)
			{
				var index = $('.StartDate').index(this);
				var d = selectedDates[0];
				if (d) {
					d = new Date(d);
					$('.EndDate:eq('+index+')').dpSetStartDate(d.addDays(1).asString());
				}
			}
	);
	$('.EndDate').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var index = $('.EndDate').index(this);
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('.StartDate:eq('+index+')').dpSetEndDate(d.addDays(-1).asString());
			}
		}
	);
	$('#units_tabs').tabs();
});
function save_rates(){
	document.prices_form.submit();
}
function delete_range(id){
	$("#price_range").val(id);
	$("#form").val('delete_range');
	document.prices_form.submit();
}
</script>
<div id="rates">
<div class="Notice">Select a unit to edit. Alternatively, if you would like to edit your personal information,
please select the "My Account" link from the menu above.</div>
<form action="" method="post" name="prices_form">
	<table border="0" width="100%">
	  <tr>
	    <td colspan="4"><h2><?php echo $unit->address;?></h2></td>
	  </tr>
	  <tr>
	    <td width="35%" class="CenterAlign"><b>Start Period</b></td>
	    <td width="35%" class="CenterAlign"><b>End Period</b></td>
	    <td width="15%" class="CenterAlign"><b>Price</b></td>
	    <td></td>
	  </tr>
	  <?php 
	  $carry_key = 0;
	  if(!empty($prices)){
	  	foreach($prices as $key=>$price){
	  ?>
	  <tr>
	    <td class="CenterAlign"><input id="start_date_<?php echo $key;?>" type="text" class="date_pick DatePeriod StartDate" name="prices[startdate][]" value="<?php echo get_string_from_date($price->startdate);?>" />
	    <input type="hidden" name="prices[id][]" value="<?php echo $price->id;?>" /></td>
	    <td class="CenterAlign"><input id="end_date_<?php echo $key;?>" type="text" class="date_pick DatePeriod EndDate" name="prices[enddate][]" value="<?php echo get_string_from_date($price->enddate);?>" /></td>
	    <td class="CenterAlign"><input size="5" type="text" class="DatePeriod" name="prices[price][]" value="<?php echo $price->price;?>" /></td>
	    <td class="CenterAlign">
	    	<a href="#" onclick="delete_range('<?php echo $price->id;?>');" title="Delete">
	    		<img alt="Delete" src="<?php echo ADMIN_COMPONENT_PATH.COMPONENT_PATH.'images/cross.png';?>">
	    	</a>
	    </td>
	  </tr>
	  <?php
	  		$carry_key++;
		 }
	  }
	  if($prices_count < 10){
	  	for($i = 0; $i < 10 - $prices_count; $i++){
	  ?>
	  <tr>
	    <td class="CenterAlign"><input id="start_date_<?php echo ($carry_key+$i);?>" type="text" class="date_pick DatePeriod StartDate" name="prices[startdate][]" /></td>
	    <td class="CenterAlign"><input id="end_date_<?php echo ($carry_key+$i);?>" type="text" class="date_pick DatePeriod EndDate" name="prices[enddate][]" /></td>
	    <td class="CenterAlign"><input size="5" type="text" class="DatePeriod" name="prices[price][]" /></td>
	    <td></td>
	  </tr>
	  <?php }
	  }
	  ?>
	</table>
	<input type="hidden" name="price_range" id="price_range" />
	<input type="hidden" name="form" id="form" value="save_rates" />
	</form>
	<?php $KToolBar->addLink('<a href="#" onclick="save_rates()"><img border="0" alt="Save" src="'.ADMIN_COMPONENT_PATH.'images/save_f2.png"/><br />Save</a>');?>
	<?php $KToolBar->addLink('<a href="?option='.COMPONENT_NAME.'&user=owner&page=home"><img border="0" alt="Cancel" src="'.ADMIN_COMPONENT_PATH.'images/cancel_f2.png"/><br />Cancel</a>');?>
</div>